home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15202 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Optimizing Const Strings
  5. Date: 3 Apr 1996 14:50:47 GMT
  6. Organization: Netcom
  7. Message-ID: <4ju387$96q@cloner2.ix.netcom.com>
  8. References: <3160B12A.41C67EA6@umich.edu>
  9. NNTP-Posting-Host: den-co11-06.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-NETCOM-Date: Wed Apr 03  6:50:47 AM PST 1996
  13. X-Newsreader: WinVN 0.99.7
  14.  
  15. In article <3160B12A.41C67EA6@umich.edu>, jmayer@umich.edu says...
  16. >
  17. >If I have an include file with a bunch of strings
  18. >in it:
  19. >
  20. >        typedef const char const * ConstStr;
  21. >        ConstStr strA = "aaa";
  22. >        ConstStr strB = "bbb";
  23. >        ConstStr strC = "ccc";
  24. >
  25. >And a program that uses only ONE of the aforementioned
  26. >strings, all of the C-compilers I've tested (CSet++ and
  27. >GCC) compile all three of the const strings into my
  28. >program, even though only one of them was used.
  29. >
  30. >Is there any way I can define these strings so that the
  31. >linker will refuse to link an unused string?
  32.  
  33. No tactic is guaranteed to work, since this is 
  34. implementation-dependent.  However, I would try:
  35.  
  36. 1) If you don't need the strings outside the module,
  37.    then declare them static and see if the compiler
  38.    is smart enough to omit them.
  39.  
  40. 2) If you might need the strings outside of the module,
  41.    then put each string in a separate module, and place
  42.    all of the modules in a library for linking.  The
  43.    linker *should* only pull in the required symbols.
  44.    However, the string-per-module overhead may
  45.    swamp any space savings you would otherwise have.
  46.  
  47. 3) You can also put them in a data file/resource file, yes?
  48.  
  49. john lilley
  50.  
  51.